<template>
	<view class="container">
		<view class="doc-login-head">
			<image src="../../static/img_doc.png" mode="widthFix"></image>
		</view>
		<view class="doc-login-con">
			<view class="doc-login-conPart">
				<view class="doc-login-conPartItem" @click="changepart(0)" :class="[loginpart == 0?'doc-login-conPartItemShow':'']"><text>注册</text></view>
				<view class="doc-login-conPartItem" @click="changepart(1)" :class="[loginpart == 1?'doc-login-conPartItemShow':'']"><text>登录</text></view>
			</view>
			<view class="doc-login-conNav">
				<view class="doc-login-conSub" v-if="loginpart == 0">
					<view class="doc-login-conNavWarp" v-if="loginzhucestatus == 0">
						<view class="doc-login-conNavWarpItem">
							<input type="text" v-model="zhucetel" value="" @input="changtelnext" placeholder-style="color:#7D8799" placeholder="请输入手机号" />
							<view v-if="zhucetel != ''" @click="zhuceclear(0)" class="doc-login-conNavWarpItemclose">
								<image src="../../static/ic_clear.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="doc-login-conNavWarpItem">
							<input type="text" v-model="zhucepass" value="" @input="changpassnext" :password="conpassword" placeholder-style="color:#7D8799" placeholder="请输入密码" />
							<view class="doc-login-conNavWarpItempass">
								<image v-if="conpassword&&zhucepass != ''" @click="changepass(0)" src="../../static/ic_eye1.png" mode="widthFix"></image>
								<image v-if="conpassword == false&&zhucepass != ''" @click="changepass(1)" src="../../static/ic_eye2.png" mode="widthFix"></image>
							</view>
							<view v-if="zhucepass != ''" @click="zhuceclear(1)" class="doc-login-conNavWarpItemclose">
								<image src="../../static/ic_clear.png" mode="widthFix"></image>
							</view>
						</view>
						<view :class="['doc-login-conNavBtn',next == true?'doc-login-Sactive':'']" @click="nextType">下一步</view>
						<!-- <view class="doc-login-Sactive">下一步</view> -->
					</view>
				</view>
				<view class="doc-login-conSub" v-if="loginpart == 1">
					<view class="doc-login-conNavWarp">
						<view class="doc-login-conNavWarpItem">
							<input type="text" v-model="logintel" value="" placeholder-style="color:#7D8799" placeholder="请输入手机号" />
							<view v-if="logintel != ''" @click="loginclear(0)" class="doc-login-conNavWarpItemclose">
								<image src="../../static/ic_clear.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="doc-login-conNavWarpItem">
							<input type="text" v-model="loginpass" value=""  :password="conpassword" placeholder-style="color:#7D8799" placeholder="请输入密码" />
							<view class="doc-login-conNavWarpItempass">
								<image v-if="conpassword&&loginpass != ''" @click="changepass(0)" src="../../static/ic_eye1.png" mode="widthFix"></image>
								<image v-if="conpassword == false&&loginpass != ''" @click="changepass(1)" src="../../static/ic_eye2.png" mode="widthFix"></image>
							</view>
							<view v-if="loginpass != ''" @click="loginclear(1)" class="doc-login-conNavWarpItemclose">
								<image src="../../static/ic_clear.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="doc-login-conNavBtn doc-login-Sactive" @click="loginbtn">登录</view>
					</view>
				</view>
				<view class="doc-login-constatus"v-if="loginpart == 0" >
					<view class="doc-login-coning" v-if="loginzhucestatus == 1">
						<view class="doc-login-coningImg">
							<image src="../../static/img_shenhe1.png" mode="widthFix"></image>
						</view>
						<text class="doc-login-coningtxt">请耐心等待，账号正在审核中....</text>
					</view>
					<view class="doc-login-coning" v-if="loginzhucestatus == 2">
						<view class="doc-login-coningImg">
							<image src="../../static/img_shenhe2.png" mode="widthFix"></image>
						</view>
						<text class="doc-login-confalsetxt">审核失败</text>
						<text class="doc-login-coningtxt">失败原因：因为{{failresion}}</text>
						<view class="doc-login-confalseBtn" @click="gozhuce">重新填写</view>
					</view>
					<view class="doc-login-coning" v-if="loginzhucestatus == 3">
						<view class="doc-login-coningImg">
							<image src="../../static/img_shenhe3.png" mode="widthFix"></image>
						</view>
						<text class="doc-login-confalsetxt">审核通过</text>
						<view class="doc-login-confalseBtn" @click="gologin">去登录</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '../../App.vue'
	export default{
		data(){
			return{
				next:false,
				loginpart:1,     //切换注册和登录
				loginzhucestatus:0,    //注册状态
				conpassword:true,
				zhucetel:'',  //注册手机号
				zhucepass: '',  //注册密码
				logintel:'',  //登录手机号
				loginpass:'',  //登录密码
				failresion:'',
			}
		},
		onLoad() {
			this.logintel = window.localStorage.getItem("account")
			this.loginpass = window.localStorage.getItem("password")
			// console.log(account)
		},
		methods:{
			// 切换登录和注册
			changepart(num){
				this.zhucetel = ''
				this.zhucepass = ''
				this.logintel = ''
				this.loginpass = ''
				this.loginpart = num
			},
			
			// 查看密码
			changepass(num){
				if(num == 0){
					this.conpassword = false
				}else{
					this.conpassword = true
				}
			},
			
			// 清除手机号或密码
			zhuceclear(num){
				if(num == 0){
					this.zhucetel = ''
				}else{
					this.zhucepass = ''
				}
			},
			// 清除手机号或密码
			loginclear(num){
				if(num == 0){
					this.logintel = ''
				}else{
					this.loginpass = ''
				}
			},
			changtelnext(){				//改变下一步的颜色
				let that = this
				if(that.zhucetel != ''&&that.zhucepass != ''){
					that.next = true
				}
			},
			changpassnext(){				//改变下一步的颜色
				let that = this
				if(that.zhucetel != ''&&that.zhucepass != ''){
					that.next = true
				}
			},
			nextType(){						//下一步
				let that = this
				if(that.next == true){
					that.loginzhucestatus = 1
					setTimeout(function(){
						app.post("api/user/register",{
							mobile:that.zhucetel,
							password:that.zhucepass,
							// mobile:15939179039,
							// password:'Wx990921'
						}).then(res=>{
							if(res.code == 1){
								that.zhucetel = ''
								that.zhucepass = ''
								that.loginzhucestatus = 3
							}else if(res.code == 0){
								that.failresion = res.msg
								that.loginzhucestatus = 2
							}
							
						}).catch(err=>{
							uni.showToast({
								title:res.msg,
								icon:'none',
								mark:true
							})
						})
					},1300)
				}
			},
			gologin(){					//去登录
				this.loginzhucestatus = 0
				this.loginpart = 1
			},
			gozhuce(){					//重新注册
				this.zhucetel = ''
				this.zhucepass = ''
				this.loginzhucestatus = 0
			},
			loginbtn(){					//登录
				let that = this
				app.post('api/user/login',{
					account:that.logintel,
					password:that.loginpass
				}).then(res=>{
					if(res.code == 1){
						console.log(res)
						let userinfo = res.data.userinfo
						uni.setStorageSync('token',userinfo.token)
						window.localStorage.setItem("account",that.logintel);
						window.localStorage.setItem("password",that.loginpass);
						if(userinfo.check_status == 1){				//check_status:审核状态:-1=未提交,0=待审核,1=已通过,2=未通过
							uni.showLoading({
								title:'登录中',
								success() {
									setTimeout(function(){
										uni.reLaunch({
											url:'/pages/doc/mine'
										})
									},1300)
								}
							})
						}else if(userinfo.check_status == -1){
							uni.showLoading({
								title:'登录中',
								success() {
									setTimeout(function(){
										uni.navigateTo({
											url:'/pages/doc/info'
										})
									},1300)
								}
							})
						}else if(userinfo.check_status == 0){
							uni.showLoading({
								title:'登陆中',
								success() {
									setTimeout(function(){
										uni.navigateTo({
											url:'/pages/doc/apply?status='+userinfo.check_status
										})
									},1300)
								}
							})
						}else if(userinfo.check_status == 2){
							uni.showLoading({
								title:'登录中',
								success() {
									setTimeout(function(){
										uni.navigateTo({
											url:'/pages/doc/apply?status='+userinfo.check_status+'&reason='+userinfo.reason
										})
									},1300)
								}
							})
						}
					}else if(res.code == 0){
						uni.showToast({
							title:res.msg,
							icon:'none',
							mark:true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title:res.msg,
						icon:'none',
						mark:true
					})
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/doclogin.css");
</style>
